/**
 * ElectronExchanger Server Header File
 * 
 * File:        protocol.h
 * Brief:       BRIEF
 * Author:      Chen Kangbing
 * Email:       ckblau@outlook.com
 * Modified:    2020/09/13 09:12:54
 *
 */


#ifndef PROTOCOL_H
#define PROTOCOL_H

#ifdef __cplusplus
extern "C" {
#endif 


#include "socket_helper.h"


#define MAX_PAIR_SIZE 16
#define MAX_KEY_LENGTH 32


typedef struct {
    int pair_size;
    char *key[MAX_PAIR_SIZE], *value[MAX_KEY_LENGTH];
    int value_size[MAX_KEY_LENGTH];
} ProtoPackTypeDef;


int protocol_decode(TransmissionTypeDef *ptrans, ProtoPackTypeDef *ppack);
char *protocol_get_value(ProtoPackTypeDef *ppack, const char *key);
char *protocol_get_value_size(ProtoPackTypeDef *ppack, const char *key, int *size);
void protocol_build_pack(ProtoPackTypeDef *ppack);
int protocol_set_value(ProtoPackTypeDef *ppack, const char *key, const char *value);
int protocol_set_value_size(ProtoPackTypeDef *ppack, const char *key, const char *value, int value_size);
void protocol_encode(ProtoPackTypeDef *ppack, TransmissionTypeDef *ptrans);


#ifdef __cplusplus
}
#endif 

#endif
